package com.example.service.impl;

import com.example.mapper.tMesProStationDataMapp;
import com.example.pojo.queryResult;
import com.example.pojo.tMesProStationDataPojo;
import com.example.service.tMesProStationDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class tMesProStationDataImpl implements tMesProStationDataService {

    @Autowired
    private tMesProStationDataMapp tMesProStationDataMapp;

    //查询发动机过站数据
    public queryResult queryStation(Map<String, Object> map){
        String engineNumber = (String) map.get("engineNumber");
        String stationId = (String) map.get("stationId");
        String timeStart = (String) map.get("timeStart");
        String timeEnd = (String) map.get("timeEnd");
        Integer page = (Integer) map.get("page");
        Integer sizePage = (Integer) map.get("sizePage");
        Integer startPage = (page - 1) * sizePage;

        //多条件查询主表数据，是否存在，将结果返回在list中
        List<tMesProStationDataPojo> partList = tMesProStationDataMapp.queryMultipleConditions(engineNumber, stationId, timeStart, timeEnd);



        //实现数据分页功能，得到起始和结束的数据行，防止索引超越限制
        int endIndex = Math.min(startPage + sizePage, partList.size());

        // 获取分页后的子列表
        List<tMesProStationDataPojo> paginatedList = partList.subList(startPage, endIndex);

        //组织数据到设定的格式内容中，将结果统一返回
        queryResult queryResult = new queryResult();
        queryResult.setData(paginatedList);
        queryResult.setTotal(partList.size());

        return queryResult;




    }

}
